package com.cq.hd.member.controller;

import com.cq.hd.common.enums.biz.BusinessGroupDefaultStateEnum;
import com.cq.hd.common.pagination.Page;
import com.cq.hd.common.response.Result;
import com.cq.hd.common.response.ResultGenerator;
import com.cq.hd.member.api.TbBusinessGroupApi;
import com.cq.hd.member.api.dto.BusinessGroupPageDto;
import com.cq.hd.member.api.dto.BusinessGroupSaveDto;
import com.cq.hd.member.api.vo.BusinessGroupPageVo;
import com.cq.hd.member.service.TbBusinessGroupService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 商家经纪人分组表 前端控制器
 * </p>
 *
 * @author mYunYu
 * @since 2023-12-07
 */
@Slf4j
@RestController
public class TbBusinessGroupController implements TbBusinessGroupApi {

    @Autowired
    private TbBusinessGroupService businessGroupService;

    @Override
    public Result<List<BusinessGroupPageVo>> selectList(BusinessGroupPageDto businessGroupPageDto) {
        businessGroupPageDto.setDefaultState(BusinessGroupDefaultStateEnum.NO.getValue()); // 过滤掉默认分组
        return ResultGenerator.success(businessGroupService.selectList(businessGroupPageDto));
    }

    @ApiOperation(value = "我的分组列表")
    @ApiResponse(response = BusinessGroupPageVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<Page<BusinessGroupPageVo>> pageBusinessGroup(BusinessGroupPageDto businessGroupPageDto) {
        return ResultGenerator.success(businessGroupService.pageBusinessGroup(businessGroupPageDto));
    }

    @ApiOperation(value = "保存分组")
    @ApiImplicitParam(name = "businessGroupSaveDto", value = "实体", required = true, paramType = "body", dataType = "BusinessGroupSaveDto")
    @ApiResponse(response = Boolean.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<Long> saveBusinessGroup(@RequestBody BusinessGroupSaveDto businessGroupSaveDto) {
        return ResultGenerator.success(businessGroupService.saveBusinessGroup(businessGroupSaveDto));
    }

    @ApiOperation(value = "删除分组")
    @ApiImplicitParam(name = "id", value = "分组id", required = true, paramType = "query", dataType = "Long")
    @ApiResponse(response = Boolean.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<Boolean> deleteBusinessGroup(Long id, Long businessId, Long agentId) {
        return ResultGenerator.success(businessGroupService.deleteBusinessGroup(id, businessId, agentId));
    }
}
